/**
  ETFRoot project, Anyang Normal University && IMP-CAS
  \class ETFAnaTask
  \brief abstract base class for tasks in the tracking stage
  \author SUN Yazhou, asia.rabbit@163.com
  \since 2021-10-04
  \date 2021-10-04 last modified
  \attention
  changelog
  <table>
  <tr>  <th>Date         <th>Author      <th>Description                   </tr>
  <tr>  <td>2021-10-04   <td>Asia Sun    <td>file created                  </tr>
  </table>

  \copyright Copyright (c) 2021 Anyang Normal U. && IMP-CAS with LGPLv3 LICENSE
*/

#ifndef ETFAnaTask_h
#define ETFAnaTask_h

#include <initializer_list>
#include <vector>
#include <string>
#include "FairTask.h"

using std::initializer_list;
using std::vector;
using std::string;

class TFolder;
class TH2F;
class ETFPXISection;
class ETFVMEEvent;
class ETFVMERawEvent;
class ETFPID;
class ETFDetectorManager;
class ETFVTrackManager;
class ETFPIDManager;
class ETFParaManager;
class ETFVisual;
class FairRootManager;

class ETFAnaTask : public FairTask{
public:
  ETFAnaTask(const char *name = "AnaTask", int verbose = 1);
  virtual ~ETFAnaTask();

  virtual void Exec(Option_t *opt);
  virtual void FinishTask();

  /// register the mapped data and recognized tracks in FairRootManager
  virtual void Register();
  virtual void WriteHistos();
  virtual void Configure(); /// user-customization -- assign the global managers

  virtual void SetChIdConfigFile(const string &file); ///< channel id maps
  virtual void SetDetPosConfigFile(const string &file); ///< detector positions
  virtual void SetDelayConfigFile(const string &file); ///< delay parameters
  virtual void SetMisConfigFile(const string &file); ///< for miscellaneous parameters
  virtual void SetConfigFolder(const string &dir); ///< set the last base folder of configFile

  virtual void SetAnaLevel(short l){ fAnaLevel = l; }
  /// analysis level: 0: no mapping; 1: 2D tracking; 2: PID; 3: 3D tracking
  virtual void AddDrawEvent(int ev){ fDrawVec.push_back(ev); }
  virtual void AddDrawEvent(const initializer_list<int> &l){ for(int i : l) AddDrawEvent(i); }
  void SetIs3DTracking(bool opt){ fIs3DTracking = opt; }
  void SetMagneticIntensity(double b);
  ETFPID *GetPID();
  void SetDetDebug(bool opt = true){ fDetDebug = opt; }
  void SetTrackingDebug(bool opt = true){ fTrackingDebug = opt; }
  void SetPIDDebug(bool opt = true){ fPIDDebug = opt; }

  ClassDef(ETFAnaTask, 1); // abstract base class for tasks in the Trackinging stage

protected:
  virtual InitStatus Init();
  virtual void CreateHistos();

  string fConfigDir; ///< containing configuration files

  bool fDetDebug;
  bool fTrackingDebug;
  bool fPIDDebug;
  bool fIs3DTracking; ///< whether do the 3D tracking
  short fAnaLevel;
  vector<int> fDrawVec; ///< event index list to be drawn

  ETFPXISection *fPXISection;
  ETFVMEEvent *fVMEEvent;
  ETFVMERawEvent *fVMERawEvent;
  ETFPID *fPID;
  // the managers //
  FairRootManager *ffm;
  ETFDetectorManager *fdm;
  ETFVTrackManager *ftm;
  ETFPIDManager *fpm;
  ETFParaManager *fParaM;
  ETFVisual *fVis;

  TFolder *fFolder; ///< folder to categorize the objects in this task
  TH2F *hTimeToTrig; ///< TimeToTrig v.s. chid
};

#endif
